package com.qeegoo.b2bautozityp.moudle.user.viewmodel;

import android.content.Intent;
import android.databinding.ObservableField;

import com.kelin.mvvmlight.command.ReplyCommand;
import com.qeegoo.b2bautozityp.api.ProgressSubscriber;
import com.qeegoo.b2bautozityp.api.RequestApi;
import com.qeegoo.b2bautozityp.api.RetrofitService;
import com.qeegoo.b2bautozityp.moudle.login.view.LoginActivity;
import com.qeegoo.b2bautozityp.moudle.user.model.UserBetailBean;

import base.lib.util.ActivityManager;

/**
 * Created by lining on 2017/9/27.
 */

public class AccountSecurityViewModel {

    private RequestApi mRequestApi;

    public AccountSecurityViewModel(RequestApi requestApi) {
        mRequestApi = requestApi;
    }

    public ObservableField<String> name = new ObservableField<>("");
    public ObservableField<String> phone = new ObservableField<>("");
    public ObservableField<String> email = new ObservableField<>("");

    //退出
    public ReplyCommand  logoutCommand = new ReplyCommand(() -> {
        Intent intent = new Intent(ActivityManager.getActivity(), LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        ActivityManager.getActivity().startActivity(intent);
        ActivityManager.getActivity().finish();
//        ToastUtils.showToast("退出");
    });
    public void loadHttp(){
        mRequestApi.getUserDetail().compose(RetrofitService.applySchedulers())
                .map(new RetrofitService.HttpResultFunc<>())
                .subscribe(new ProgressSubscriber<UserBetailBean>() {
                    @Override
                    public void onNext(UserBetailBean userBetailBean) {
                        name.set(userBetailBean.getName());
                        phone.set(userBetailBean.getPhone());
                        email.set(userBetailBean.getEmail());
                    }
                });
    }
}
